package java8.stream;

import cn.hutool.core.lang.Assert;
import java8.User;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Reduce {

    public static void main(String[] args) {
        List<User> javaProgrammers = new ArrayList<User>() {
            {
                add(new User(1l, "Jaycob", "Java programmer", 50, 18));
                add(new User(2l, "Brittany", "PHP programmer", 60, 55));
                add(new User(3l, "Donny", "PHP programmer", 101, 25));
                add(new User(4l, "Jonie", "Java programmer", 35020, 15));
                add(new User(5l, "Hervey", "Java programmer", 2272, 25));
                add(new User(6l, "Jaimie", "Java programmer", 2057, 87));
                add(new User(7l, "Randall", "Java programmer", 3120, 99));
                add(new User(8l, "Corrina", "Java programmer", 345, 25));
                add(new User(9l, "Dene", "Java programmer", 3375, 14));
                add(new User(10l, "Pam", "Java programmer", 3426, 20));
            }
        };

        Optional<Integer> reduce = javaProgrammers.stream().filter(s -> s.getSalary() < 1000)
                .map(s -> s.getSalary())
                .reduce((x, y) -> x += y);
        System.out.println(reduce.get());

        User first = javaProgrammers.stream().filter(s -> s.getSalary() < 10).findFirst().orElse(null);

        System.out.println("first" +  first);

        List<User> list = javaProgrammers.stream().filter(s -> s.getSalary() < 50).collect(Collectors.toList());
        User aPHP_programmer = list.stream().filter(s -> s.getSchool().equals("aPHP programmer"))
                .findFirst().orElse(null);
        System.out.println("第二次---》" + aPHP_programmer);
        Assert.isTrue(true);

    }
}